package server

import (
	"encoding/json"
	"goods_rpc/database/redis"
	"goods_rpc/internal/model"
	pb "goods_rpc/proto/goods"
)

// 新增商品
func CreateGoods(in *pb.CreateGoodsRequest) (*model.Goods, error) {
	g := model.Goods{
		GoodsImages:  in.GoodsImages,
		GoodsName:    in.GoodsName,
		GoodsPrice:   float64(in.GoodsPrice),
		GoodsStock:   in.GoodsStock,
		GoodsSales:   in.GoodsSales,
		GoodsStatus:  in.GoodsStatus,
		AuditsStatus: in.AuditsStatus,
		AuditsGroup:  1,
	}
	goods, err := g.CreateGoods()
	if err != nil {
		return nil, err
	}
	m, _ := json.Marshal(goods)
	//同步商品
	redis.SetRedisGoods(int(goods.ID), string(m))
	return goods, nil

}
